<template>
    <up-popup class="pointPopup" :safeAreaInsetTop="true"  mode="top" :overlay="false" zIndex="10175" :duration="200" :show="show" :round="10" @close="close" @open="openCallback">
        <up-navbar bgColor="#7099B4" :safeAreaInsetTop="true" >
            <template #left>
              <up-icon size="35" :name="geodetic"></up-icon>
              <up-text text="大地測量站" color="#fff"></up-text>
            </template>

          <template #right>
              <up-icon size="28" :name="closePng" color="#fff"  @click="close"></up-icon>
          </template>
        </up-navbar>
      <view class="content">
      <up-gap height="45" bgColor="#ffffff00"></up-gap>
          <up-row customStyle="margin-bottom: 10px">
              <up-col span="12">
                  <h1>STATION NO. {{ detailInfo.STN_NO }}</h1>
              </up-col>
          </up-row>
          <up-row customStyle="margin-bottom: 10px">
              <up-col span="6">
                  <up-text type="info" text="文件編號:"></up-text>
              </up-col>
              <up-col>
                  <up-text v-if="detailInfo?.SOURCE=='product'&&detailInfo?.ORDERSTATUS!=1" text="--"></up-text>
                  <up-text v-else :text="detailInfo?.CF_NO ? detailInfo?.CF_NO : '--'"></up-text>
              </up-col>
          </up-row>
          <up-row customStyle="margin-bottom: 10px">
              <up-col span="6">
                  <up-text type="info" text="测量站编号:"></up-text>
              </up-col>
              <up-col>
                  <up-text :text="detailInfo.STN_NO"></up-text>

              </up-col>
          </up-row>
          <up-row customStyle="margin-bottom: 10px">
              <up-col span="6">
                  <up-text type="info" text="标记种类:"></up-text>
              </up-col>
              <up-col>
                <template v-if="detailInfo?.SOURCE=='product'">
                  <up-text :text="detailInfo?.LAYER"></up-text>
                </template>
                <template v-else>
                  <up-text v-if="detailInfo?.LAYER=='traverse_point'" text="导线站"></up-text>
                  <up-text v-if="detailInfo?.LAYER=='trig_point'" text="三角网测站"></up-text>
                  <up-text v-if="detailInfo?.LAYER=='bm_point'" text="水准点"></up-text>
                </template>
              </up-col>
          </up-row>
          <up-row customStyle="margin-bottom: 10px">
              <up-col span="6">
                  <up-text type="info" text="坐标北:"></up-text>
              </up-col>
              <up-col>
                <up-text v-if="detailInfo?.SOURCE=='product'&&detailInfo?.ORDERSTATUS!=1" text="--"></up-text>
                <up-text v-else :text="detailInfo?.NORTHING_M ? detailInfo?.NORTHING_M : '--'"></up-text>
              </up-col>
          </up-row>
          <up-row customStyle="margin-bottom: 10px">
              <up-col span="6">
                  <up-text type="info" text="坐标东:"></up-text>
              </up-col>
              <up-col>
                <up-text v-if="detailInfo?.SOURCE=='product'&&detailInfo?.ORDERSTATUS!=1" text="--"></up-text>
                <up-text v-else :text="detailInfo?.EASTING_M ? detailInfo?.EASTING_M : '--'"></up-text>
              </up-col>
          </up-row>
          <up-row customStyle="margin-bottom: 10px">
              <up-col span="6">
                  <up-text type="info" text="香港高程基准以上高度:"></up-text>
              </up-col>
              <up-col>
                <up-text v-if="detailInfo?.SOURCE=='product'&&detailInfo?.ORDERSTATUS!=1" text="--"></up-text>
                <up-text v-else :text="detailInfo?.HKPD_M ? detailInfo?.HKPD_M : '--'"></up-text>
              </up-col>
          </up-row>

        <up-gap height="50" bgColor="#ffffff00"></up-gap>
        <view class="btn-content">
          <up-button v-if="detailInfo?.SOURCE=='share'||(detailInfo?.SOURCE=='product'&&detailInfo?.ORDERSTATUS==1)" icon="share-square" @click="openDocument" iconColor="#fff" color="#242d40" class="addCartBtn" textColor="#E1FFD8">
              Open Document
          </up-button>
            <up-gap height="10" bgColor="#ffffff00"></up-gap>
          <up-button icon="chat" @click="leaveFeedback" iconColor="#fff" color="#242d40" class="addCartBtn" textColor="#E1FFD8">
              Leave feedback
          </up-button>
        </view>
        <up-gap height="30" bgColor="#ffffff00"></up-gap>
      </view>
  </up-popup>
</template>

<script setup  lang="ts">
import { ref ,defineExpose} from 'vue';
import tab from '@/plugins/tab'
import closePng from '@/static/images/close.png'
import j8Ico from '@/static/icon/J8.png'
import hk1980 from '@/static/icon/hk1980.png'
import geodetic from '@/static/icon/geodetic.png'
import { HKMAPsearchgeodetic } from '@/api/system/map'
import config from '@/config'

import { mapStore } from '@/stores'

const domainName = config.baseUrl;

const mapStoreFun = mapStore();

// 创建响应式数据
const show = ref(false);

const systemInfo = uni.getSystemInfoSync();

const detailInfo:any = ref({})

const emit = defineEmits<{
  (e: 'onSearchFor', key: string, coordinates: any[]): void,
}>()

// 定义方法
function open(data:any) {
  mapStoreFun.SUM_MAPTYPE(1)
  searchgeodetic(data)
  show.value = true;
}

function openCallback() {
}

function leaveFeedback(){
    const name = detailInfo.value?.STN_NAME ? detailInfo.value.STN_NAME : "";
    const no = detailInfo.value?.STN_NO ? detailInfo.value.STN_NO : "";
    const id = detailInfo.value?.pId ? detailInfo.value.pId : detailInfo.value?.productId ? detailInfo.value.productId : "";
    tab.navigateTo('/pages/common/feedbackview/index?id='+id+'&name='+name+'&no='+no)
}

function openDocument() {
  // console.log(1111,detailInfo.value);
  // if(detailInfo.value?.stnNo){
      let PDF_URl = domainName+'/profile/upload/geodetic/'+detailInfo.value.STN_NO+'.pdf'
      if(detailInfo.value?.SOURCE=='product' && detailInfo.value?.ORDERSTATUS=='1' && detailInfo.value?.PDF_URl && detailInfo.value?.PDF_URl.length>0 && detailInfo.value?.PDF_URl[0]?.filePath){
        PDF_URl = domainName+detailInfo.value?.PDF_URl[0]?.filePath
      }
      // let PDF_URl = domainName+'/profile/upload/geodetic/2036.011.pdf'
      // let PDF_URl = 'https://www.geodetic.gov.hk/summarysheet/2036.011.pdf';
      const pdfUrl = encodeURIComponent(PDF_URl)
      const title = detailInfo.value?.STN_NAME ? detailInfo.value.STN_NAME : detailInfo.value.STN_NO+".PDF";
        if(systemInfo.platform == 'android'){
            plus.runtime.openURL(PDF_URl);
        }else{
        tab.navigateTo('/pages/common/webview/index?title='+title+'&url='+pdfUrl)
        }
  // }
}


function searchgeodetic (info:any){
    HKMAPsearchgeodetic(info.STN_NO).then((data:any) => {
      if(data.rows.length>0){
        detailInfo.value = data.rows[0]
        selectCard(data.rows[0])
      }else{
        detailInfo.value = {}
      }
    }).catch(error => {
        detailInfo.value = {}
      console.error("获取数据失败:", error);
    })
}

function close() {
  mapStoreFun.SUM_MAPTYPE(-1)
  show.value = false;
}

function selectCard(item: any) {
  emit('onSearchFor', item?.STN_NO, [item?.X,item?.Y]);
}

defineExpose({
  open,
  close
});
</script>

<style scoped>
.pointPopup .content {
    padding: 20rpx;
    background-color: #fff;
    border-radius: 10rpx;
    min-height:45vh;
    /* position: absolute; */
  }
</style>

